#include "widget.h"
#include "ui_widget.h"
#include<QShortcut>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    ui->horizontalSlider->setMinimum(0);
    ui->horizontalSlider->setMaximum(100);
    ui->horizontalSlider->setSingleStep(1);
    ui->horizontalSlider->setValue(0);
    QShortcut* shortCut1=new QShortcut(this);
    shortCut1->setKey(QKeySequence("-"));
    connect(shortCut1,&QShortcut::activated,this,&Widget::subValue);

    QShortcut* shortCut2=new QShortcut(this);
    shortCut2->setKey(QKeySequence("+"));
    connect(shortCut2,&QShortcut::activated,this,&Widget::addValue);


}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_horizontalSlider_valueChanged(int value)
{
    ui->label->setText(QString::number(value));

}

void Widget::subValue()
{
    int Value=ui->horizontalSlider->value();
    if(Value>=2)
        ui->horizontalSlider->setValue(Value);
}

void Widget::addValue()
{
     int Value=ui->horizontalSlider->value();
     if(Value<100)
         ui->horizontalSlider->setValue(Value+2);
}
